<?php 
Class photoController extends appController
{
	
     public function index()
	{
		$this->assign('cat_list',Model('menu')->get_parent_menu(2));
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
		$sort['cat_id']=intval($_GET['c']);
		$sort['keyword']=isset($_GET['k'])?trim($_GET['k']):'';
		$art_list=Model('photo')->photo_list($page,$sort);
		$this->assign('search_action','1');
		$this->assign('album_id',$album_id);
		$this->assign('photo_list',$art_list['data']);
		$this->assign('photo_page',$art_list['pagelink']);
	
		$this->display('photo_list.html');
	
	}
	
	public function photo_order()
	{
		$id=isset($_POST['id'])?intval($_POST['id']):'';
		$val=isset($_POST['val'])?intval($_POST['val']):'';
		$result=Model('photo')->photo_order($val,$id);
		print_r(json_encode($result));
	}
	
	

	
	public function del_photo() 
	{
		$id=isset($_REQUEST['id'])?$_REQUEST['id']:'';
		if(is_array($id))
		{
			foreach($id as $k=>$v)
			{
				$result=Model('photo')->del_photo($v);
			}
		}
		else
		{
			$result=Model('photo')->del_photo($id);
		}
		print_r(json_encode($result));
	}
	public function add_photo()
	{
		
		$this->assign('parent_list',Model('menu')->get_parent_menu(2));
		$this->assign('ur_here','>添加相片');
		$album_id=isset($_GET['album_id'])?intval($_GET['album_id']):'';
		$this->assign('album_id',$album_id);
		$this->assign('action','insert_photo');
		$this->display('photo.html');
	}
	public function insert_photo()
	{
		$en_abstract=isset($_POST['en_abstract'])?$_POST['en_abstract']:'';
		$en_title=isset($_POST['en_title'])?$_POST['en_title']:'';
		$info['title']=isset($_POST['title'])?CH_SC.$_POST['title'].DIG_EC.EN_SC.$en_title.DIG_EC:'';
		$info['cat_id']=isset($_POST['cat_id'])?intval($_POST['cat_id']):'';
		$info['abstract']=isset($_POST['abstract'])?CH_SC.$_POST['abstract'].DIG_EC.EN_SC.$en_abstract.DIG_EC:'';
		$info['original_pic']=isset($_POST['thumb_url'])?$_POST['thumb_url']:'';
		$info['album_id']=isset($_POST['album_id'])?intval($_POST['album_id']):'';
		
			$data=array('error'=>0,'content'=>'','url'=>'');
		if(Model('photo')->insert_photo($info))
		{
			$data['content']=Lang('SUCCESS_ADD');
			$data['url']="index.php?g=admin&m=photo&a=index";
			
		}
		else
		{
			$data['content']=Lang('INVALID_OPERATION');
			//$data['url']=$_SERVER['REQUEST_URI'];
		}
		$this->showMsg($data);
	
	}
	public function update_photo()
	{
		$en_abstract=isset($_POST['en_abstract'])?$_POST['en_abstract']:'';
		$en_title=isset($_POST['en_title'])?$_POST['en_title']:'';
	$info['title']=isset($_POST['title'])?CH_SC.$_POST['title'].DIG_EC.EN_SC.$en_title.DIG_EC:'';
		$info['cat_id']=isset($_POST['cat_id'])?intval($_POST['cat_id']):'';
		$info['abstract']=isset($_POST['abstract'])?CH_SC.$_POST['abstract'].DIG_EC.EN_SC.$en_abstract.DIG_EC:'';
		$info['original_pic']=isset($_POST['thumb_url'])?$_POST['thumb_url']:'';
		$id=isset($_POST['id'])?intval($_POST['id']):'';
		
		
			$data=array('error'=>0,'content'=>'','url'=>'');
		if(Model('photo')->update_photo($info,$id))
		{
			$data['content']=Lang('SUCCESS_EDIT');
			$data['url']="index.php?g=admin&m=photo&a=index";
			
		}
		else
		{
			$data['content']=Lang('INVALID_OPERATION');
			//$data['url']=$_SERVER['REQUEST_URI'];
		}
		$this->showMsg($data);
	
	}
	public function edit_photo()
	{
		$this->assign('parent_list',Model('menu')->get_parent_menu(2));
		$this->assign('ur_here','>编辑相片');
		$id=isset($_GET['id'])?intval($_GET['id']):'';
		$this->assign('id',$id);
		$art_info=Model('photo')->get_photo($id);
		
		$this->assign('photo',$art_info);
		$this->assign('action','update_photo');
		$this->display('photo.html');
	
	}
	
 
	
	public function file()
	{
		
		$file=current($_FILES);
		$result=array('error'=>0,'url'=>$file['name']);
			$thumb_url=Model('image')->upload_image($file, 'photo/'.date('Ym'));
		$result['url']=$thumb_url;
		$result['url']=$thumb_url;
		
		$result['message']='';
		print_r(json_encode($result));
		exit();
	}
	
	

	
	
}